package com.kongyz.filter;

import com.kongyz.Person;

import java.util.List;

/**
 * @author kongyz
 * @date 2018/6/27 22:02
 * @Description:
 */
public class OrCriteria implements Criteria {
    private Criteria criteria;
    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    public List<Person> meetCriteria(List<Person> personList) {
        List<Person> firstCriteriaItems=criteria.meetCriteria(personList);
        List<Person> otherCriteriaItems=otherCriteria.meetCriteria(personList);
        //把2个集合的数据合在一起，并去重
        //把在other中，不在first的值添加到first
        for (Person person:otherCriteriaItems){
            if(!firstCriteriaItems.contains(person)){
                firstCriteriaItems.add(person);
            }
        }
        return firstCriteriaItems;
    }
}
